//
//  SetUpViewController.m
//  PrintPort
//
//  Created by 华谕 on 2017/11/15.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "SetUpViewController.h"
#import "RetrievePasswordViewController.h"
#import "BuyBackPasswordViewController.h"

static NSString *cellPath = @"SetUpCell";
@interface SetUpViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)NSArray *titAry;
@property (nonatomic, strong)NSArray *imgAry;

@end

@implementation SetUpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _titAry = @[@"修改登录密码",@"设置提现密码"];
    [self creatUI];
}

- (void)creatUI
{
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = BacksColor;
    self.navigationItem.title = @"设置";
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-SCREER_HeiX-STA_NAV_HEIGHT) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.backgroundColor = BacksColor;
    [self.view addSubview:_tableview];
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 2;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
   
    if (indexPath.section == 0)
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//        UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 17.5*displaywidth, 15*displaywidth, 15*displaywidth) ImageName:_imgAry[indexPath.row]];
//        imgView.contentMode = UIViewContentModeScaleAspectFit;
//        [cell.contentView addSubview:imgView];
        UILabel *namelab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 5*displaywidth, 120*displaywidth, 40*displaywidth) Font:14.0 Text:_titAry[indexPath.row] Color:RGB(77, 77, 77)];
        [cell.contentView addSubview:namelab];
        if (indexPath.row != _titAry.count-1)
        {
            UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(15*displaywidth, 49, SCREEN_WIDTH-15*displaywidth, 1*displaywidth)];
            lineview.backgroundColor = LinesColor;
            [cell.contentView addSubview:lineview];
        }
        
    }
    else
    {
        UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 25*displaywidth)];
        myView.backgroundColor = BacksColor;
        [cell.contentView addSubview:myView];
        UILabel *titlab = [ZCControl createLabelWithFrame:CGRectMake(0, 25*displaywidth, SCREEN_WIDTH, 50*displaywidth) Font:16.0 Text:@"退出登录" Color:RGB(77, 77, 77)];
        titlab.textAlignment = NSTextAlignmentCenter;
        [cell.contentView addSubview:titlab];
       
        
    }
    return cell;
    
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        if (indexPath.row == 0)
        {
            RetrievePasswordViewController *Vc = [[RetrievePasswordViewController alloc] init];
            Vc.titleString = @"修改密码";
            [self.navigationController pushViewController:Vc animated:YES];
        }
        else
        {
            BuyBackPasswordViewController *vc = [[BuyBackPasswordViewController alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
        
    }
    else
    {
        [self requestUserLogout];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1)
    {
        return 75*displaywidth;
    }
    return 50*displaywidth;
}



- (void)requestUserLogout
{
    WEAKSELF;
    [HYBaseHandler requestUserLogoutParmers:nil Success:^(id obj)
     {
         if ([obj server_Getcodecheck])
         {
             [LTools storage:NO ForKey:SERVER_IsLogin];
             [LTools cache:@"" ForKey:SERVER_LoginToken];
             [LTools showMBProgressWithText:@"退出成功" addToView:sharedDelegate.window];
             [weakSelf.navigationController popViewControllerAnimated:YES];
         }
         else
         {
             
         }
     } failed:^(NSError *error) {
         
     }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
